package com.mc2.docapp.disabilityassessmenttool.LowerLimb;

import io.realm.RealmObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class C_llca_hip extends RealmObject {
    private LLCustDataType flexion_extension_arc = new LLCustDataType();
    private LLCustDataType internal_external_rotation_arc = new LLCustDataType();
    private LLCustDataType adduction_abduction_arc = new LLCustDataType();
    private LLInnerCalculations inner_calculations = new LLInnerCalculations();

    public void calc(C_llca_hip c_llca_hip) {
        double a = c_llca_hip.getFlexion_extension_arc().getActual_right();
        double b = c_llca_hip.getAdduction_abduction_arc().getActual_right();
        double c = c_llca_hip.getInternal_external_rotation_arc().getActual_right();
        double pa = perc(a, c_llca_hip.getFlexion_extension_arc().getNormal());
        double pb = perc(b, c_llca_hip.getAdduction_abduction_arc().getNormal());
        double pc = perc(c, c_llca_hip.getInternal_external_rotation_arc().getNormal());
        double x = (pa + pb + pc) / 3.0;
        c_llca_hip.getFlexion_extension_arc().setPerc_loss_right(pa);
        c_llca_hip.getAdduction_abduction_arc().setPerc_loss_right(pb);
        c_llca_hip.getInternal_external_rotation_arc().setPerc_loss_right(pc);

        a = c_llca_hip.getFlexion_extension_arc().getActual_left();
        b = c_llca_hip.getAdduction_abduction_arc().getActual_left();
        c = c_llca_hip.getInternal_external_rotation_arc().getActual_left();
        pa = perc(a, c_llca_hip.getFlexion_extension_arc().getNormal());
        pb = perc(b, c_llca_hip.getAdduction_abduction_arc().getNormal());
        pc = perc(c, c_llca_hip.getInternal_external_rotation_arc().getNormal());
        double y = (pa + pb + pc) / 3.0;
        c_llca_hip.getFlexion_extension_arc().setPerc_loss_left(pa);
        c_llca_hip.getAdduction_abduction_arc().setPerc_loss_left(pb);
        c_llca_hip.getInternal_external_rotation_arc().setPerc_loss_left(pc);

        c_llca_hip.setInner_calculations(new LLInnerCalculations(
                x,
                y,
                x * 0.35,
                y * 0.35
        ));
    }

    private double perc(double a, double normal) {
        return ((normal - a) * 100d) / (normal + 0d);
    }

}
